<template>
  <div style="padding: 24px">
    <h2>激活码价格表</h2>
    <el-table :data="tableData" border style="width: 100%">
      <el-table-column type="index" width="50"> </el-table-column>
      <el-table-column label="VIP时长" width="180">
        <template slot-scope="scope">
          <span>
            {{scope.row.dictLabel == "99999" ? "永久" : scope.row.dictLabel + "天"  }}
          </span>
        </template>
      </el-table-column>
      <el-table-column label="价格" prop="dictValue"> </el-table-column>
      <el-table-column label="购买地址" prop="remark"> </el-table-column>
      <el-table-column fixed="right" label="操作" width="100">
        <template slot-scope="scope">
          <el-button @click="handleAdd(scope.row)" type="text" size="small"
            >修改</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-dialog title="修改价格" :visible.sync="dialogFormVisible">
      <el-form :model="form">
        <el-form-item label="VIP时长" :label-width="formLabelWidth">
          <el-input
            disabled
            v-model="form.dictLabel"
            autocomplete="off"
          ></el-input>
        </el-form-item>
        <el-form-item label="价格" :label-width="formLabelWidth">
          <el-input v-model="form.dictValue" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="购买地址" :label-width="formLabelWidth">
          <el-input
            type="textarea"
            v-model="form.remark"
            autocomplete="off"
          ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="handleSubmit">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import request from "@/utils/request";
export default {
  data() {
    return {
      tableData: [],
      dialogFormVisible: false,
      form: {
        dictLabel: "",
        dictValue: 0,
        remark: "",
      },
      formLabelWidth: "120px",
    };
  },
  created() {
    this.getSaleList();
  },
  methods: {
    getSaleList() {
      request({
        url: "/bus/outer/dictData/vip_price",
        method: "get",
      }).then((res) => {
        this.tableData = res.data;
      });
    },
    handleAdd(data) {
      let info = JSON.parse(JSON.stringify(data));
      this.form=info;
      this.dialogFormVisible = true;
    },
    handleSubmit() {
      this.dialogFormVisible = false;
       request({
        url: "/system/dict/data",
        method: "put",
        data:this.form
      }).then((res) => {
          console.log(res);
          this.getSaleList()
      });
      console.log(this.form);
    },
    selectImg(e) {
      console.log(e);
    },
    handleDelete(e) {
      console.log(e);
    },
    handleRemove(file, fileList) {
      console.log(file, fileList);
    },
    handlePreview(file) {
      console.log(file);
    },
  },
};
</script>